package gxb.test07;

public class Runs {
    public static void main(String[] args) {
        final int FLIPS =100;
        int currentRun =0;
        int maxRun =0;
        Coin coin = new Coin();
        for (int i = 0; i < FLIPS; i++) {
            coin.flip();
            if (coin.isHeads()) {
                currentRun++;
                if (currentRun > maxRun) {
                    maxRun = currentRun;
                }
            } else {
                currentRun = 0;
            }
        }
        System.out.println("最大连续HEADS次数：" + maxRun);
    }
}
class Coin {
    public final int HEADS=0;
    public final int TAILS=1;
    private int face;

    public Coin(){
        flip();
    }
    public void flip(){
        face = (int) (Math.random()*2);
    }
    public boolean isHeads(){
        return (face == HEADS);
    }
    public String toString(){
        String faceName;
        if (face == HEADS)
            faceName="Heads";
        else
            faceName = "Tails";
        return faceName;
    }
}
